package com.stox.ui.swing.widget;

import java.awt.Component;

import com.stox.design.Callback;
import com.stox.ui.swing.util.SwingUtil;
import com.stox.ui.swing.view.NavigatorTab;
import com.stox.ui.swing.widget.wrapper.JTabbedPane;

@org.springframework.stereotype.Component
public class NavigatorTabbedPane extends JTabbedPane {
	private static final long serialVersionUID = 3588208810928628057L;

	public void setSelectedIndex(int index) {
		final NavigatorTab tab = (NavigatorTab) getComponentAt(index);
		if (tab != null && !tab.isInitialized()) {

			new Thread() {
				@Override
				public void run() {
					super.run();
					SwingUtil.executeInFreeze((Component) tab,
							new Callback<Object, Object>() {
								@Override
								public Object execute(Object payload) {
									tab.initialize();
									return null;
								}
							}, null);
				}
			}.start();
		}
		super.setSelectedIndex(index);
	};
}
